package com.asdc.demo.ack;

import com.asdc.demo.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 * @ClassName ProducerAck
 * @Author bsy
 * @Description Ack 消息应答机制
 * 模拟场景：
 *  1、生产者生产消息，消费者01正常, 消费者02异常
 * 消息列表：
 * ack-01
 * ack-02
 * ack-03
 * ack-04
 *
 *  2、正常：消费者01消费一个，消费者02 消费一个，是轮询的方式
 *
 *  3、预期结果：消费者02挂机后，消息重新入队，消费者01替他正常消费
 *
 * @Date 2022/3/12 16:18
 * @Version 1.0
 */
public class ProducerAck {
    private static final String QUEUE_NAME = "QUEUE_ACK_VVYX";

    public static void main(String[] args) throws Exception {
        try (Channel channel = RabbitMqUtils.getChannel()) {
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入:");
            while (scanner.hasNext()){
                String msg = scanner.next();
                channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
            }
        }
    }
}
